package com.tzbank.wisdom.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.tzbank.wisdom.service.UserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 用户控制器
 *
 */
@Api(tags = { "用户控制器" })
@RequestMapping("user")
@RestController
public class UserController {

	@Autowired
	private UserService userService;

	/**
	 * 用户登录
	 * 
	 * @param userJson
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/logon")
	@ApiOperation(value = "登录", notes = "登录接口")
	public Map<String, Object> logon(@RequestBody Map<String, String> reqBody) {
		return userService.logon(reqBody);
	}

	@ResponseBody
	@PostMapping(value = "/logout")
	@ApiOperation(value = "安全退出", notes = "安全退出")
	public Map<String, Object> logout(@RequestBody Map<String, String> reqBody) {
		return userService.logout(reqBody);
	}
	
	
	/**
	 * 登陆后强制修改密码
	 * 
	 * @param reqBody
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/reset")
	@ApiOperation(value = "登陆后强制修改密码", notes = "登陆后强制修改密码")
	public Map<String, Object> resetPassword(@RequestBody Map<String, String> reqBody) {
		return userService.resetPassword(reqBody,0);
	}
	
	
	/**
	 * 修改密码
	 * 
	 * @param reqBody
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/updatePassword")
	@ApiOperation(value = "修改回密码接口", notes = "修改密码接口")
	public Map<String, Object> updatePassword(@RequestBody Map<String, String> reqBody) {
		return userService.resetPassword(reqBody,1);
	}
	
	
	/**
	 * 找回密码
	 * 
	 * @param reqBody
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/retrieve")
	@ApiOperation(value = "找回密码接口", notes = "找回密码接口")
	public Map<String, Object> retrievePassword(@RequestBody Map<String, String> reqBody) {
		return userService.retrievePassword(reqBody);
	}
	
	
	
	/**
	 * 获取验证码
	 * @param reqBody
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/getCode")
	@ApiOperation(value = "获取验证码", notes = "找回密码接口")
	public Map<String, Object> getAutCode(@RequestBody Map<String, String> reqBody) {
		return userService.sendAuthCode(reqBody);
	}
	
	
	@ResponseBody
	@PostMapping(value = "/checkCode")
	@ApiOperation(value = "校验验证码", notes = "找回密码接口")
	public Map<String, Object> checkCode(@RequestBody Map<String, String> reqBody) {
		return userService.checkCode(reqBody);
	}

	/**
	 * 推送消息测试接口
	 * 
	 * @param reqBody
	 * @return
	 */
	@ResponseBody
	@PostMapping(value = "/push")
	public Map<String, Object> pushMsg(@RequestBody Map<String, String> reqBody) {
		return userService.pushMsg(reqBody);
	}
}
